﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dm;
using System.Data;
namespace WebApplication1
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Cache["key"] == null)
            {
                string strconn = "server=10.2.0.36;database=旧襄阳市市本级;User Id=SYSDBA;PWD=SYSDBA";
                //DmConnection conn = new DmConnection(strconn);
                string sql = "select  top  100 * from 旧襄阳市市本级.分析表_近三年税款征收数据表 a,旧襄阳市市本级.分析表_近三年税款征收数据表 b,旧襄阳市市本级.分析表_近三年税款征收数据表 c where a.个人姓名=b.个人姓名 and b.个人姓名=c.个人姓名";
                DmDataAdapter oda = new DmDataAdapter(sql, strconn);
                DataTable dt = new DataTable();
                Cache.Insert("key", dt, null, DateTime.Now.AddSeconds(100), System.Web.Caching.Cache.NoSlidingExpiration);
                oda.Fill(dt);//填充datatable
                dt.Dispose();//释放资源
                oda.Dispose();//释放资源
                this.GridView1.DataSource = dt;//给数据控件绑定数据源datatable
                this.GridView1.DataBind();//刷新数据控件的数据源
            }
            else
            {
                this.GridView1.DataSource = Cache["key"];
                this.GridView1.DataBind();//控件绑定数据之后，需要刷新的
            }
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
            {
                //保持列不变形 
                for (int i = 0; i < e.Row.Cells.Count; i++)
                {
                    //方法一： 
                    e.Row.Cells[i].Text = " " + e.Row.Cells[i].Text + " ";
                    e.Row.Cells[i].Wrap = false;
                    //方法二： 
                    //e.Row.Cells[i].Text = "<nobr> " + e.Row.Cells[i].Text + " </nobr>"; 
                }
            }
        }

    }
}

